import request from '../utils/request'
//学员考试信息获取，分页
export const stuExamInfoGet = (page = 1, num: number, search: any = {}) => {
    let skip = (page - 1) * num
    for (let attr in search) {
        if (!search[attr]) {
            delete search[attr]
        }
    }
    if (search.name) {
        search.name = { "$regex": search.name, "$options": "i" }
    }
    if (search.tel) {
        search.tel = { "$regex": search.tel, "$options": "i" }
    }
    if (search.cardId) {
        search.cardId = { "$regex": search.cardId, "$options": "i" }
    }
    if (search.school) {
        search.school = { "$regex": search.school, "$options": "i" }
    }
    if (search.class) {
        search.class = { "$regex": search.class, "$options": "i" }

    }
    if (search.subjectState) {
        search.subjectState = { "$regex": search.subjectState, "$options": "i" }
    }
    return request.get("classes/student", {
        params: {
            limit: num,
            skip,
            count: 1,
            where: search
        }
    })
}
// 修改学员考试信息
interface stuExamInfoPutobjType{
    name?: string;
    subject?: string;
    progress?: string;
    progressTime?: string;
    cardId?: string;
    tel?: string;
    class?: string;
    comment?: string;
    subjectState?: string;
    referrer?: string;
    count?: string;
    passTime?: string;
    coach?: string;
    schoolName?: string;
    carType?: string;
    state?: string;
    completeTime?: string;
}
export const stuExamInfoPut = (id: string, obj:stuExamInfoPutobjType) => {
    return request.put(`classes/student/${id}`, obj)
}

//批量学员考试信息
export const stuExamBatchPut = (ids: Array<string>, obj:any) => {
    console.log("请求接收信息：",ids,obj);
    
    let requests = ids.map((id) => {
        return {
            method: "PUT",
            //path是后端接口，严格按照文档配置路径
            path: `/1.1/classes/student/${id}`,
            body: obj
        };
    });
    return request.post("batch", { requests });
};


//学员模拟考试信息获取，分页
export const mockExamGet = (page = 1, num: number, search: any = {}) => {
    let skip = (page - 1) * num
    for (let attr in search) {
        if (!search[attr]) {
            delete search[attr]
        }
    }
    if (search.name) {
        //模糊查询，使用正则
        search.name = { "$regex": search.name, "$options": "i" }
    }
    if (search.subject) {
        //模糊查询，使用正则
        search.subject = { "$regex": search.subject, "$options": "i" }

    }
    if(search.cardId=="cardId"){
        delete search.cardId
    }
    return request.get("classes/MockExam", {
        params: {
            limit: num,
            skip,
            count: 1,
            where: search
        }
    })
}
//删除学员模拟考试信息
export const mockExamrDel = (Id:string) => {
    return request.delete(`classes/MockExam/${Id}`)
}

interface batchForm {
    state: string,
    completeTime: string,
    comment: string,
    coach?:string
}

//批量修改模拟成绩
export const mockBatchPut = (ids: Array<string>, obj: batchForm) => {
    let requests = ids.map((id) => {
        return {
            method: "PUT",
            //path是后端接口，严格按照文档配置路径
            path: `/1.1/classes/MockExam/${id}`,
            body: obj
        };
    });
    return request.post("batch", { requests });
};
//获取校区信息
export const schoolNameGet=()=>{
    return request.get("/classes/school")
}
//获取教练信息
export const coachGet = (conditon:{carType:string, schoolName:string,object:string}) => {
    return request.get(`classes/coachList`, {
        params: {
            where: conditon
        }
    })
}
//获取科目进度信息
export const subjectGet=(id:string)=>{
    return request.get("/classes/process",{
        params:{
            where:{parentId:id}
        }
    })
}
//获取学员预考记录信息
export const preExamGet = (page = 1, num: number, search: any = {}) => {
    let skip = (page - 1) * num
    for (let attr in search) {
        if (!search[attr]) {
            delete search[attr]
        }
    }
    if (search.name) {
        //模糊查询，使用正则
        search.name = { "$regex": search.name, "$options": "i" }
    }
    if (search.subject) {
        //模糊查询，使用正则
        search.subject = { "$regex": search.subject, "$options": "i" }
    }
    if(search.cardId=="cardId"){
        delete search.cardId
    }
    return request.get("classes/preExam", {
        params: {
            limit: num,
            skip,
            count: 1,
            where: search
        }
    })
}
//删除学员预约考试信息
export const preExamrDel = (Id:string) => {
    return request.delete(`classes/preExam/${Id}`)
}
